///////////////////////////////////////////////////////////////////////////////
//
// Licensed under the MIT License
//
// Copyright (c) 2010 Chris Colinsky
// All Rights Reserved
//
// version	0.5
// http://code.google.com/p/sugarcookie/
// http://code.google.com/p/sugarcookie/wiki/License
//
////////////////////////////////////////////////////////////////////////////////

package sugarcookie.data.vo {
	import sugarcookie.data.handlers.xml.XHTMLHandler;
	
	/**
	 * Value Object used when parsing XHTML.
	 */
	public class Anchor extends Object {
		private var _xml:XML;
		private var _href:String;
		//  value stored in rel attribute
		private var _type:String;
		// value stored in rev attribute
		private var _tracking:String;
		private var _name:String;
		private var _title:String;
		private var _value:String;
		private var _index:uint;
		private var _images:Array = [];
		private var _click:String;
		
		public function Anchor(_a:XML,_i:uint=0) {
			_xml = _a;
			_index = _i;
			
			if (_xml.@rel=="internal" && String(_xml.@href)!="#") _href = String(_xml.@href).split("#")[1];
			else _href = _xml.@href;
			
			var iList:XMLList = _xml.img;
        	for (var i:int=0;i<iList.length();i++) {
        		var img:Img = new Img(iList[i]);
        		_images[img.title] = img;
        	}
			
			_type = _xml.@rel;
			_tracking = _xml.@rev;
			_value = XHTMLHandler.cleanHTML(_xml.children());
			
			_title = _xml.attribute("title")!=undefined?_xml.@title:"title"+String(int(Math.random()*1000));
			_name = _xml.attribute("name")!=undefined?_xml.@name:"link";
			_click = _xml.attribute("onclick")!=undefined?_xml.@onclick:null;
		}
		
		public function get xml():XML {
			return _xml;
		}
		
		public function get html():String {
			return "<a href='event:"+_name+"'>"+_value+"</a>";
		}
		
		public function get index():uint {
			return _index;
		}
		
		public function get childNode():String {
			return _value;
		}
		
		public function get images():Array {
        	return _images;
        }
		
		public function get href():String {
			return _href;
		}
		
		public function get type():String {
			return _type;
		}
		
		public function get tracking():String {
			return _tracking;
		}
		
		public function get name():String {
			return _name;
		}
		
		public function get title():String {
			return _title;
		}
		
		public function get click():String {
			return _click;
		}
	}
}